package com.mtw.bbs.util;

import cn.hutool.core.collection.CollectionUtil;
import com.mtw.bbs.common.core.vo.Result;
import com.mtw.bbs.userAdmin.pojo.dto.UserDto;
import com.mtw.bbs.userAdmin.pojo.vo.UserInfoVo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ArticleUtils {



    /**
     * 用户信息转VO
     * @param result    调用结果
     * @return           map(key:用户id，v：发帖人信息VO)
     */

    public static Map<String, UserInfoVo> getUserInfoVoMap2R(Result<List<UserDto>> result){

        Map<String, UserInfoVo> userMap = new HashMap<>(16);
        if (result.isSuccess() && CollectionUtil.isNotEmpty(result.getData())){
            result.getData().forEach(u->{
                UserInfoVo infoVO = u.toSimpleInfoVO();
                userMap.put(u.getId(),infoVO);
            });
        }
        return userMap;
    }



    /**
     * 用户信息转VO
     * @param result    调用结果
     */

    public static UserInfoVo userInfoVoToR(Result<UserDto> result){

        if (result.isSuccess() && result.getData() != null){
            return result.getData().toSimpleInfoVO();
        }
        return new UserInfoVo();
    }

}
